package com.imot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.imot.mapper.EmaRecordMapper;
import com.imot.mapper.TargetParametersMapper;
import com.imot.pojo.entity.Dict;
import com.imot.pojo.entity.EmaRecord;
import com.imot.pojo.vo.DeviceForecastVO;
import com.imot.pojo.vo.DevicePredictionVO;
import com.imot.pojo.vo.DevicePridictVO;
import com.imot.response.Result;
import com.imot.service.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * ClassName: FutureTrendsSmpl
 * Description:
 * date: 2023/11/18 15:03
 *
 * @author imot-jiah.wang
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class FutureTrendsServiceImpl implements FutureTrendsService {
    private final IEmaRecordShortTermService emaRecordShortTermService;
    private final IEmaRecordMidTermService emaRecordMidTermService;
    private final IEmaRecordExtendedTermService emaRecordExtendedTermService;
    private final IEmaRecordLongTermService emaRecordLongTermService;
    private final IEmaRecordService emaRecordService;
    private final EmaRecordMapper emaRecordMapper;
    private final IDictService dictService;
    private final ITargetParametersService targetParametersService;
    private final TargetParametersMapper targetParametersMapper;
    private final IEmaErrorRecordService emaErrorRecordService;
    private final EmaRecordMapper recordMapper;
    private final IErrorThresholdsService errorThresholdsService;

    @Override
    public Result analyzeTrends(String name) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime startTime = now.minusDays(1);
        LocalDateTime endTime = now.plusDays(1);

        List<EmaRecord> list = emaRecordService.list();
        LambdaQueryWrapper<Dict> dictLambdaQueryWrapper = new LambdaQueryWrapper<>();
        dictLambdaQueryWrapper.gt(Dict::getId,10000);
        dictLambdaQueryWrapper.lt(Dict::getId,20000);
        List<Dict> list1 = dictService.list(dictLambdaQueryWrapper);
        List<String> parameterName = list1.stream().map(Dict::getName).collect(Collectors.toList());

        List<Map<String,Object>> waveList = recordMapper.getDateWave(startTime,endTime,"","");

        return Result.success(waveList);
    }

    @Override
    public Result predictFailure(String name,String model) {
        List<Map<String, Object>> hashMaps = new ArrayList<>();

        //时间
        String time = null;
        //置信度
        String confidenceLevel = null;
        //失效时间
        String failureTimeInHours = null;
        //失效率
        String failureRatePercentage = null;

        return null;
    }

    @Override
    public Result historicalPredictions() {
        DevicePridictVO devicePridictVO = new DevicePridictVO();
        return Result.success(devicePridictVO);
    }

    @Override
    public Result getHistoryPage(LocalDateTime startTime, LocalDateTime endTime, String deviceName) {


        ArrayList<DevicePredictionVO> devicePredictionVOS = new ArrayList<>();
        return Result.success(devicePredictionVOS);
    }

    @Override
    public Result getHistoryDetail(Integer id) {
        DeviceForecastVO deviceForecastVO = new DeviceForecastVO();
        return Result.success(deviceForecastVO);
    }
}

